#include "FolderComponent.h"

FolderComponent::FolderComponent (const String& directoryPath)
{
	String basePath = File::getCurrentWorkingDirectory().getFullPathName();
	String toFolderPath = "/res/" + directoryPath;
	String thePath = basePath + toFolderPath;

	DirectoryIterator directoryIterator(File(thePath), false, JUCE_T("*"), File::findFilesAndDirectories);

	while(directoryIterator.next())
	{
		File file(directoryIterator.getFile());
		FolderItemComponent * fic = new FolderItemComponent(file);
		addAndMakeVisible(fic);
		items.add(fic);
		
	}
}

FolderComponent::~FolderComponent()
{
}

void FolderComponent::getFile(const int& i)
{

}

void FolderComponent::setPath(const String& directoryPath)
{

}

void FolderComponent::paint (Graphics& g)
{}	

void FolderComponent::resized()
{
	int xRow = 3;
	int margin = 5;
	int dim = 50;
	int numElems = items.size();
	for(int i = 0; i < numElems; i++)
	{
		FolderItemComponent * item = items.getUnchecked(i);
		item->setBounds((i%xRow) * dim + margin, (floor((float)(i/xRow))) * margin + margin, dim, dim);
	}
}
